package cn.hiapi.shopkeeper.service.fields;

import cn.hiapi.interfaces.DispatchContext;
import cn.hiapi.interfaces.account.IAccountInfoService;
import cn.hiapi.shop.entity.shop.Shop;
import cn.hiapi.shop.service.shop.ShopService;
import cn.hiapi.utils.JsonUtils;
import com.alibaba.fastjson.JSONObject;
import org.springframework.stereotype.Service;

/**
 * @author AdinZ
 * @date 2023/2/15 21:19
 */
@Service
public class FieldsShopService implements IAccountInfoService {
    private final DispatchContext dispatchContext;

    public FieldsShopService(DispatchContext dispatchContext) {
        this.dispatchContext = dispatchContext;

    }

    @Override
    public String getField() {
        return "base-shop-fid";
    }

    @Override
    public JSONObject getData(long mid, long uid) {
        Shop shop = this.dispatchContext.getServiceOne(ShopService.class).get(uid);
        if (shop != null)
            return JsonUtils.builder().put("logo", shop.getLogo()).put("name", shop.getName()).put("id", shop.getId()).build();
        return null;
    }
}
